package com.designpatterns.behavioral.iterator;

public class NameRepository implements Container {
    public String[] names = {"Robert", "John", "Julie", "Lora"};

    @Override
    public Iterator getIterator() {
        return new NameIterator();
    }

    private class NameIterator implements com.designpatterns.behavioral.iterator.Iterator {
        private Integer index = 0;

        @Override
        public Boolean hasNext() {
            if (index < names.length) {
                return true;
            }

            return false;
        }

        @Override
        public Object next() {
            if (this.hasNext()) {
                return names[index++];
            }

            return null;
        }
    }
}
